﻿using Identity.API.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace Identity.API.Services
{
    public class UserClaimsRepository : IUserClaimsRepository
    {
        private readonly ApplicationDbContext _context;
        public UserClaimsRepository(ApplicationDbContext context)
        {
            _context = context;
        }
       
        public async Task AddAsync(Microsoft.AspNetCore.Identity.IdentityUserClaim<string> userClaim)
        {
           await  _context.UserClaims.AddAsync(userClaim);
        }
        public void Update(Microsoft.AspNetCore.Identity.IdentityUserClaim<string> userClaim)
        {
            _context.UserClaims.Update(userClaim);
        }
        public async Task<Microsoft.AspNetCore.Identity.IdentityUserClaim<string>> FindByIdAsync(int claimsId)
        {
            return await _context.UserClaims.FindAsync(claimsId);
        }
        public async Task<Microsoft.AspNetCore.Identity.IdentityUserClaim<string>> FindByUserIdAsync(string userId)
        {
            var userClaim = _context.UserClaims.Where(t => t.UserId == userId).FirstOrDefault();
            return await Task.FromResult(userClaim);
        }
        public void DeleteById(Microsoft.AspNetCore.Identity.IdentityUserClaim<string> userClaim)
        {
            _context.UserClaims.Remove(userClaim);
        }
    }
}
